<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // setTimeout
        // serTimeout(() => console.log(111), 0)
        // console.log(222);
        // promise和async
        let task1 = () => {
            console.log('this is task1'); // 2
        }
        let task2 = () => {
            console.log('this is task2'); // 7
        }
        // async
        async function demo() {
            console.log('demo is start'); // 1
            await task1();
            await task2();
            console.log('demo is end'); // 8
        }
        // 调用
        demo();
        // 外部输出
        console.log('this is outside1'); // 3
        // promise对象
        new Promise((resolve, reject) => {
            console.log('promise is start'); // 4
            setTimeout(() => {
                console.log('timeout is start'); // 9
                console.log('timeout is end'); // 10
                resolve('异步完成');
            }, 0)
            console.log('promise is end'); // 5
        }).then(res => console.log(res)) // 11
        // 外部输出
        console.log('this is outside2'); // 6
    </script>
</body>
</html>